package sis.studentinfo;

import static org.junit.Assert.assertEquals;
import static sis.studentinfo.DateUtil.createDate;

import java.util.Date;

import org.junit.Before;
import org.junit.Test;



public class CourseSessionTest  {
	
	private CourseSession session;
	private static final int CREDITS = 3;
	
	@Before
	public void setUp() {
		this.session = createCourseSession();
	}

	@Test
	public void testCreate() {
		assertEquals("ENGL", session.getDepartment());
		assertEquals("101", session.getNumber());
		assertEquals(0, session.getNumberOfStudents());
	}
	
	@Test
	public void testEnrollStudents() {
		Student student1 = new Student("Cain Divoe");
		session.enrool(student1);
		assertEquals(CREDITS, student1.getCredits());
		assertEquals(1, session.getNumberOfStudents());
		assertEquals(student1, session.get(0));
		
		Student student2 = new Student("Coralee Devaughn");
		session.enrool(student2);
		assertEquals(CREDITS, student2.getCredits());
		assertEquals(2, session.getNumberOfStudents());
		assertEquals(student1, session.get(0));
		assertEquals(student2, session.get(1));
	}
	
	@Test
	public void testCount() {
		CourseSession.resetCount();
		createCourseSession();
		assertEquals(1, CourseSession.getCount());
		createCourseSession();
		assertEquals(2, CourseSession.getCount());
		createCourseSession();
		assertEquals(3, CourseSession.getCount());
	}
	
	private CourseSession createCourseSession() {
		CourseSession session = CourseSession.Create("ENGL", "101", createDate(2003, 1, 6));
		session.setNumberOfCredits(CREDITS);
		return session;
	}
	
	@Test
	public void TestCourseDate() {
		Date sixteenWeeksOut = createDate(2003, 4, 25);
		assertEquals(sixteenWeeksOut, session.getEndDate());
	}
	
}
